/**
 * @param {number} x
 * @param {number} n
 * @return {number}
 */
var myPow = function (x, n) {
  let absN = Math.abs(n)
  if (absN === 0) return 1.0
  if (n === 1) return x
  if (n === -1) return 1 / x
  let remain = {}
  const myPow1 = (x, n) => {
    if (n % 2) {
      n = Math.floor(n / 2)
      remain[x] = 1
    } else {
      n = n / 2
    }
    if (n === 1) {
      return x * x
    } else {
      return myPow1(x * x, n)
    }
  }
  let pow = myPow1(x, absN)

  const res = Object.keys(remain).reduce((pre, cur) => {
    return pre * cur
  }, pow)
  return n > 0 ? res : 1 / res
}
console.log(myPow(8.95371, -1))
